package cn.itcast.controller;

import cn.itcast.common.R;
import cn.itcast.dto.SetmealDto;
import cn.itcast.entity.Page;
import cn.itcast.entity.Setmeal;
import cn.itcast.service.ISetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/setmeal")
@Api(tags = "套餐相关接口")
public class SetMealController {
    @Autowired
    private ISetmealService setmealService;

    @PostMapping
    @ApiOperation("新增套餐接口")
    public R<String> save(@RequestBody SetmealDto setmealDto){
      setmealService.save(setmealDto);
      return R.success("添加成功");
    }

    @GetMapping("/page")
    @ApiOperation("分页查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",required = true,value = "页码"),
            @ApiImplicitParam(name = "pageSize",required = true,value = "页面大小"),
            @ApiImplicitParam(name = "name",value = "套餐名")
    })
    public R<Page<SetmealDto>> page(Integer page,Integer pageSize,String name){
     Page<SetmealDto> pageInfo = setmealService.findByName(page,pageSize,name);
        return R.success(pageInfo);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐接口")
    public R<SetmealDto> findById(@PathVariable Long id){

     SetmealDto setmealDto =setmealService.findById(id);
     return R.success(setmealDto);
    }

    @DeleteMapping()
    @ApiOperation("删除套餐接口")
    public R<String> delete(Long[] ids){
        setmealService.delete(ids);

        return R.success("删除成功");
    }
    @GetMapping("/list")
    @ApiOperation("根据分类Id和状态查询套餐菜品接口")
    public R<List<SetmealDto>> list(Long categoryId,Integer status){
          List<SetmealDto> list = setmealService.list(categoryId,status);
          return R.success(list);

    }
    @GetMapping("/dish/{setmealId}")
    @ApiOperation("查询套餐菜品接口")
    public R<List<Map<String,Object>>> findSetmealDish(@PathVariable Long setmealId) {
        List<Map<String,Object>> setmealDishes = setmealService.findSetmealDish(setmealId);
        return R.success(setmealDishes);
    }
}
